package org.csu.onlineedubackend.entity;



import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.csu.onlineedubackend.util.JsonUtil;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

@Data
@TableName("question")
public class Question implements Serializable {
    @TableId(type = IdType.AUTO)
    private Integer id;

    @TableField("course_id")
    private Integer courseId;

    private String title; // 作业标题

    private String type; // 'single', 'multiple', 'judge', 'blank'

    private String content;

    private String options; // JSON 字符串

    private String answer;

    private Integer score; // 分值

    private String level; // '易', '中', '难'

    private String tags; // JSON 字符串

    @TableField("resource_urls")
    private String resourceUrls; // JSON 字符串，存储多个 URL

    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime; // 创建时间
    
    /**
     * 获取资源 URL 列表
     * @return URL 列表
     */
    @com.fasterxml.jackson.annotation.JsonIgnore
    public List<String> getResourceUrlList() {
        return JsonUtil.jsonToUrls(this.resourceUrls);
    }
    
    /**
     * 设置资源 URL 列表
     * @param urls URL 列表
     */
    @com.fasterxml.jackson.annotation.JsonIgnore
    public void setResourceUrlList(List<String> urls) {
        this.resourceUrls = JsonUtil.urlsToJson(urls);
    }
    
    /**
     * 添加一个资源 URL
     * @param url 要添加的 URL
     */
    @com.fasterxml.jackson.annotation.JsonIgnore
    public void addResourceUrl(String url) {
        List<String> urls = getResourceUrlList();
        urls.add(url);
        setResourceUrlList(urls);
    }
}